package com.zwan.oam_rtc.utils.messages;

import com.zwan.oam_rtc.utils.wintcp.ByteTransfer;

import java.nio.ByteBuffer;

/*(SDSMsgHead) + 请求消息结构*/
public class RtcmsResponse extends AbstractStruct {
    private SDSMsgHead msgHead = new SDSMsgHead();
    private byte[] body = new byte[Const.MAX_MSG_BODY_LEN];
    private short total;
    private short current;

    public RtcmsResponse() {
        super();
    }

    public void readFromBuffer(ByteBuffer bf) {
        msgHead.readFromBuffer(bf);
        total = bf.getShort();
        current = bf.getShort();
        body = new byte[bf.limit() - bf.position()];
        bf.get(body);
    }

    public void writeToBuffer(ByteBuffer bf) {
        msgHead.writeToBuffer(bf);
        bf.putShort(total);
        bf.putShort(current);
        bf.put(body);
    }


    public int getLength() {
        return msgHead.getLength() + 1 + 2 + 2 + body.length;
    }

    //get set
    public String getBody() {
        return ByteTransfer.getUTF8String(body);
    }

    public int getBodyLen() {
        return body.length;
    }

    public void setBody(String strBody) {
        if (body != null) {
            ByteTransfer.str2Byte(strBody, this.body);
        }
    }

    public SDSMsgHead getMsgHead() {
        return msgHead;
    }

    public void setMsgHead(SDSMsgHead msgHead) {
        this.msgHead = msgHead;
    }

    public short getTotal() {
        return total;
    }

    public void setTotal(short total) {
        this.total = total;
    }

    public short getCurrent() {
        return current;
    }

    public void setCurrent(short current) {
        this.current = current;
    }
}
